package com.wxxymakers.grademark.model.entity;

import com.baomidou.mybatisplus.annotation.*;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @author 
 */
@Data
@TableName(value = "wx_item", resultMap = "joinAllMap")
public class WxItem implements Serializable {
    @TableId(value = "Id", type = IdType.AUTO)
    private Integer id;

    /**
     * 项目名
     */
    @TableField(condition = SqlCondition.LIKE)
    private String name;

    /**
     * 类型id 废弃
     */
    private String typeId;

    /**
     * 是不是加分项目,默认是
     */
    @JsonProperty("isAdd")
    @TableField("is_add")
    private Boolean tisAdd;

    /**
     * 是否需要结项
     */
    private Boolean needEnd;

    /**
     * 是否能自己填分数
     */
    private Boolean canWrite;

    /**
     * 是否唯一，一次事件是否可以添加多个
     */
    private Boolean only;

    /**
     * 项目允许参与人数 默认一个人
     */
    private Integer peopleNum;

    @TableField(exist = false)
    private List<WxItemPlace> places = new ArrayList<>();

    /**
     * 项目级别数量 统计出来的
     */
    @TableField(exist = false)
    private Integer rankNum;

    @TableField(exist = false)
    private List<WxItemRank> ranks = new ArrayList<>();

    /**
     * 最大分值
     */
    private Float maxScore;

    /**
     * 发布者id
     */
    private Integer publishId;

    /**
     * 发布时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
    private Date datetime;

    /**
     * 项目备注
     */
    private String comment;

    private static final long serialVersionUID = 1L;


    public void setRanks(List<WxItemRank> ranks) {
        this.ranks = ranks;
        if (ranks.isEmpty()) {
            WxItemRank rank = new WxItemRank();
            rank.setName("默认等级");
            rank.setRatio(1F);
            this.ranks.add(rank);
        }
        this.rankNum = ranks.size();
    }

    public void setPlaces(List<WxItemPlace> places) {
        this.places = places;
        if (places.isEmpty()) {
            WxItemPlace place = new WxItemPlace();
            place.setPlace(1);
            place.setRatio(1F);
            this.places.add(place);
        }
        this.peopleNum = places.size();
    }
}